home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / getcwd.pl < prev    next >
Encoding:
Text File  |  1999-12-28  |  1.0 KB  |  57 lines

  1.  
  2. sub getcwd
  3. {
  4.     local($dotdots, $cwd, @pst, @cst, $dir, @tst);
  5.  
  6.     unless (@cst = stat('.'))
  7.     {
  8.     warn "stat(.): $!";
  9.     return '';
  10.     }
  11.     $cwd = '';
  12.     do
  13.     {
  14.     $dotdots .= '/' if $dotdots;
  15.     $dotdots .= '..';
  16.     @pst = @cst;
  17.     unless (opendir(getcwd'PARENT, $dotdots))            #'))
  18.     {
  19.         warn "opendir($dotdots): $!";
  20.         return '';
  21.     }
  22.     unless (@cst = stat($dotdots))
  23.     {
  24.         warn "stat($dotdots): $!";
  25.         closedir(getcwd'PARENT);                    #');
  26.         return '';
  27.     }
  28.     if ($pst[$[] == $cst[$[] && $pst[$[ + 1] == $cst[$[ + 1])
  29.     {
  30.         $dir = '';
  31.     }
  32.     else
  33.     {
  34.         do
  35.         {
  36.         unless (defined ($dir = readdir(getcwd'PARENT)))        #'))
  37.         {
  38.             warn "readdir($dotdots): $!";
  39.             closedir(getcwd'PARENT);                #');
  40.             return '';
  41.         }
  42.         unless (@tst = lstat("$dotdots/$dir"))
  43.         {
  44.         }
  45.         }
  46.         while ($dir eq '.' || $dir eq '..' || $tst[$[] != $pst[$[] ||
  47.            $tst[$[ + 1] != $pst[$[ + 1]);
  48.     }
  49.     $cwd = "$dir/$cwd";
  50.     closedir(getcwd'PARENT);                    #');
  51.     } while ($dir ne '');
  52.     chop($cwd);
  53.     $cwd;
  54. }
  55.  
  56. 1;
  57.